<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";
%>
<html>
<head>
    <base href="<%=basePath%>">
    <meta charset="UTF-8">

    <link href="jquery/bootstrap_3.3.0/css/bootstrap.min.css" type="text/css" rel="stylesheet"/>
    <script type="text/javascript" src="jquery/jquery-1.11.1-min.js"></script>
    <script type="text/javascript" src="jquery/bootstrap_3.3.0/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="common/js/common.js"></script>

    <script type="text/javascript">

        //默认情况下取消和保存按钮是隐藏的
        var cancelAndSaveBtnDefault = true;

        $(function () {
            $("#remark").focus(function () {
                if (cancelAndSaveBtnDefault) {
                    //设置remarkDiv的高度为130px
                    $("#remarkDiv").css("height", "130px");
                    //显示
                    $("#cancelAndSaveBtn").show("2000");
                    cancelAndSaveBtnDefault = false;
                }
            });
            $("#cancelBtn").click(function () {
                //显示
                $("#cancelAndSaveBtn").hide();
                //设置remarkDiv的高度为130px
                $("#remarkDiv").css("height", "90px");
                cancelAndSaveBtnDefault = true;
            });
            $("#remarkDivList").on("mouseover", ".remarkDiv", function () {
                $(this).children("div").children("div").show();
            });
            $("#remarkDivList").on("mouseout", ".remarkDiv", function () {
                $(this).children("div").children("div").hide();
            });
            $("#remarkDivList").on("mouseover", ".myHref", function () {
                $(this).children("span").css("color", "red");
            });
            $("#remarkDivList").on("mouseout", ".myHref", function () {
                $(this).children("span").css("color", "#E6E6E6");
            });



            // 查询线索备注列表信息
            queryClueRemarkList();

            // 给保存添加单击事件
            $("#saveCreateClueRemarkBtn").on("click", function () {
                // 判断内容
                var noteContent = $.trim($("#remark").val());
                if (!noteContent) {
                    alert("备注内容不能位空")
                    return
                }
                // 获取id标识
                var clueId = "${clue.id}";
                // 发起请求
                $.ajax({
                    url: "workbench/clue/saveCreateClueRemarkBtn.do",
                    type: "post",
                    data: {
                        noteContent: noteContent,
                        clueId: clueId
                    },
                    success: function (data) {
                        if (data.code === 1000) {
                            // 清空信息
                            $("#remark").val("");
                            // 刷新
                            queryClueRemarkList()
                        } else {
                            alert(data.message)
                        }
                    }
                });

            });

            // 给更新添加单击事件
            $("#updateRemarkBtn").on("click", function () {
                var noteContent = $("#edit-noteContent").val();
                if (!noteContent) {
                    alert("请输入编辑内容！")
                    return
                }
                $.ajax({
                    url: "workbench/clue/editClueRemark.do",
                    type: "post",
                    data: {
                        id: $("#remarkId").val(),
                        noteContent: noteContent
                    },
                    success: function (data) {
                        if (data.code === 1000) {
                            alert("更新成功")
                            $("#editClueRemarkModal").modal("hide")
                            queryClueRemarkList()
                        } else {
                            alert(data.message)
                        }
                    }
                })
            });

            // 查询线索参与的市场活动
            queryActivityByClueId();

            // 加载线索关联市场活动页面
            $("#bindActivityBtn").on("click", function () {
                $("#tBody").html("");
                $("#bindModal").modal("show");
            });

            // 给输入框添加键盘监听事件
            $("#searchActivityName").on("keyup", function () {
                var searchActivityName = $.trim($("#searchActivityName").val());
                var clueId = "${clue.id}";
                $.ajax({
                    url: "workbench/clue/searchActivityByClueId.do",
                    type: "get",
                    data: {
                        searchActivityName: searchActivityName,
                        clueId: clueId
                    },
                    success: function (data) {
                        if (data.code === 1000) {
                            // 循环遍历字符串拼接
                            var str = "";
                            $.each(data.body, function (index, obj) {
                                str += "<tr>";
                                str += "<td><input type=\"checkbox\" value=\"" + obj.id + "\"/></td>";
                                str += "<td>" + obj.name + "</td>";
                                str += "<td>" + obj.startDate + "</td>";
                                str += "<td>" + obj.endDate + "</td>";
                                str += "<td>" + obj.owner + "</td>";
                                str += "</tr>";
                            })
                            $("#tBody").html(str)
                        } else {
                            alert(data.message)
                        }
                    }

                })

            });

            // 给关联市场活动中关联单击事件
            $("#saveBindActivityBtn").on("click", function () {

                var checkedAll = $("#tBody input:checked");
                if (checkedAll.length == 0) {
                    alert("请选择要添加的记录")
                    return
                } else {
                    var clueId = "${clue.id}";
                    var str = "";
                    $.each(checkedAll,function (index,obj) {
                        str += "id="+$(obj).val()+"&";
                    })
                    str = str+"clueId="+clueId;
                    $.ajax({
                        url: "workbench/clue/saveBindActivityBtn.do",
                        type: "post",
                        data:str,
                        success: function (data) {
                            if (data.code === 1000){
                                alert("关联成功")
                                // 关闭窗口
                                $("#bindModal").modal("hide")
                                queryActivityByClueId();
                            } else {
                                alert(data.message)
                            }

                        }
                    })
                }
            });

            // 给转换添加单击事件
            $("#convertPageBtn").on("click",function () {
                var clueId = "${clue.id}"
                window.location.href="workbench/clue/convertPage.do?id="+clueId;
            })

        });

        // 查询线索备注列表信息
        function queryClueRemarkList() {
            var clueId = "${clue.id}"
            // 发起请求
            $.ajax({
                url: "workbench/clue/queryClueRemarkList.do",
                type: "get",
                data: "clueId=" + clueId,
                success: function (data) {
                    if (data.code === 1000) {
                        var fullName = "${clue.fullName}"
                        var appellation = "${clue.appellation}"
                        var company = "${clue.company}"
                        // 成功
                        var str = "";
                        $.each(data.body, function (index, obj) {
                            str += "<div  class=\"remarkDiv\" style=\"height: 60px;\">";
                            str += "<img title=\"" + obj.createBy + "\" src=\"image/user-thumbnail.png\" style=\"width: 30px; height:30px;\">";
                            str += "<div style=\"position: relative; top: -40px; left: 40px;\" >";
                            str += "<h5>" + obj.noteContent + "</h5>";
                            str += "<font color=\"gray\">线索</font> <font color=\"gray\">-</font> <b>" + fullName + appellation + "-" + company + "</b> <small style=\"color: gray;\"> " + obj.createTime + " 由" + obj.createBy + "</small>";
                            str += "<div style=\"position: relative; left: 500px; top: -30px; height: 30px; width: 100px; display: none;\">";
                            str += "<a class=\"myHref\" onclick=\"editClueRemark('" + obj.id + "','" + obj.noteContent + "')\" href=\"javascript:void(0);\"><span class=\"glyphicon glyphicon-edit\" style=\"font-size: 20px; color: #E6E6E6;\"></span></a>";
                            str += "&nbsp;&nbsp;&nbsp;&nbsp;";
                            str += "<a class=\"myHref\" onclick=\"deleteClueRemark('" + obj.id + "')\" href=\"javascript:void(0);\"><span class=\"glyphicon glyphicon-remove\" style=\"font-size: 20px; color: #E6E6E6;\"></span></a>";
                            str += "</div>";
                            str += "</div>";
                            str += "</div>";
                        })
                        $("#remarks").html(str)

                    } else {
                        alert(data.message)
                    }
                }
            });
        };

        // 跳转至修改线索备注页面
        function editClueRemark(id, noteContent) {
            var id = $("#remarkId").val(id);
            var noteContent = $("#edit-noteContent").val(noteContent);
            $("#editClueRemarkModal").modal("show");

        };

        // 线索详情备注删除
        function deleteClueRemark(id) {
            if (confirm("您真的要删除吗？")) {
                $.ajax({
                    url: "workbench/clue/deleteClueRemark.do",
                    type: "post",
                    data: {
                        id: id,
                    },
                    success: function (data) {
                        if (data.code === 1000) {
                            alert("删除成功")
                            queryClueRemarkList()
                        } else {
                            alert(data.message)
                        }
                    }

                })
            }
        };

        // 查询线索参与的市场活动
        function queryActivityByClueId() {
            // 获取标识
            var clueId = "${clue.id}"
            $.ajax({
                    url: "workbench/clue/queryActivityByClueId.do",
                    type: "get",
                    data: {
                        clueId: clueId
                    },
                    success: function (data) {
                        if (data.code === 1000) {
                            // 字符串拼接
                            var str = "";
                            $.each(data.body, function (index, obj) {
                                str += "<tr>";
                                str += "<td>" + obj.name + "</td>";
                                str += "<td>" + obj.startDate + "</td>";
                                str += "<td>" + obj.endDate + "</td>";
                                str += "<td>" + obj.owner + "</td>";
                                str += "<td><a href=\"javascript:void(0);\" onclick=\"deleteClueCorrelate('"+obj.id+"') ;\" style=\"text-decoration: none;\"><span class=\"glyphicon glyphicon-remove\"></span>解除关联</a></td>";
                                str += "</tr>";
                            });
                            $("#relationTBody").html(str);
                        } else {
                            alert(data.message)
                        }
                    }
                }
            )
        }

        // 接触线索参与的市场活动
        function deleteClueCorrelate(activityId) {
            var clueId = "${clue.id}";
            if (confirm("您真的要解除关联吗?")){
                $.ajax({
                    url:"workbench/clue/deleteClueCorrelate.do",
                    type:"post",
                    data:{
                        activityId:activityId,
                        clueId:clueId
                    },
                    success:function (data) {
                        if (data.code === 1000){
                            queryActivityByClueId();
                        } else {
                            alert(data.message)
                        }

                    }
                })
            }
        }
    </script>

</head>
<body>

<!-- 关联市场活动的模态窗口 -->
<div class="modal fade" id="bindModal" role="dialog">
    <div class="modal-dialog" role="document" style="width: 80%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">×</span>
                </button>
                <h4 class="modal-title">关联市场活动</h4>
            </div>
            <div class="modal-body">
                <div class="btn-group" style="position: relative; top: 18%; left: 8px;">
                    <form class="form-inline" role="form">
                        <div class="form-group has-feedback">
                            <input id="searchActivityName" type="text" class="form-control" style="width: 300px;"
                                   placeholder="请输入市场活动名称，支持模糊查询">
                            <span class="glyphicon glyphicon-search form-control-feedback"></span>
                        </div>
                    </form>
                </div>
                <table id="activityTable" class="table table-hover" style="width: 900px; position: relative;top: 10px;">
                    <thead>
                    <tr style="color: #B3B3B3;">
                        <td><input type="checkbox" id="checkedAll"/></td>
                        <td>名称</td>
                        <td>开始日期</td>
                        <td>结束日期</td>
                        <td>所有者</td>
                        <td></td>
                    </tr>
                    </thead>
                    <tbody id="tBody">

                    </tbody>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button id="saveBindActivityBtn" type="button" class="btn btn-primary">关联</button>
            </div>
        </div>
    </div>
</div>

<!-- 修改线索详情备注的模态窗口 -->
<div class="modal fade" id="editClueRemarkModal" role="dialog">
    <%-- 备注的id --%>
    <input type="hidden" id="remarkId">
    <div class="modal-dialog" role="document" style="width: 40%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">×</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">修改备注</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" role="form">
                    <input type="hidden" id="edit-id">
                    <div class="form-group">
                        <label for="edit-noteContent" class="col-sm-2 control-label">内容</label>
                        <div class="col-sm-10" style="width: 81%;">
                            <textarea class="form-control" rows="3" id="edit-noteContent"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="updateRemarkBtn">更新</button>
            </div>
        </div>
    </div>
</div>

<!-- 返回按钮 -->
<div style="position: relative; top: 35px; left: 10px;">
    <a href="javascript:void(0);" onclick="window.history.back();"><span class="glyphicon glyphicon-arrow-left"
                                                                         style="font-size: 20px; color: #DDDDDD"></span></a>
</div>

<!-- 大标题 -->
<div style="position: relative; left: 40px; top: -30px;">
    <div class="page-header">
        <h3>${clue.fullName}${clue.appellation} <small>${clue.company}</small></h3>
    </div>
    <div style="position: relative; height: 50px; width: 500px;  top: -72px; left: 700px;">
        <button id="convertPageBtn" type="button" class="btn btn-default"><span class="glyphicon glyphicon-retweet"></span>
            转换
        </button>

    </div>
</div>

<br/>
<br/>
<br/>

<!-- 详细信息 -->
<div style="position: relative; top: -70px;">
    <div style="position: relative; left: 40px; height: 30px;">
        <div style="width: 300px; color: gray;">名称</div>
        <div style="width: 300px;position: relative; left: 200px; top: -20px;">
            <b>${clue.fullName}${clue.appellation}</b></div>
        <div style="width: 300px;position: relative; left: 450px; top: -40px; color: gray;">所有者</div>
        <div style="width: 300px;position: relative; left: 650px; top: -60px;"><b>${clue.owner}</b></div>
        <div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -60px;"></div>
        <div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -60px; left: 450px;"></div>
    </div>
    <div style="position: relative; left: 40px; height: 30px; top: 10px;">
        <div style="width: 300px; color: gray;">公司</div>
        <div style="width: 300px;position: relative; left: 200px; top: -20px;"><b>${clue.company}</b></div>
        <div style="width: 300px;position: relative; left: 450px; top: -40px; color: gray;">职位</div>
        <div style="width: 300px;position: relative; left: 650px; top: -60px;"><b>${clue.job}</b></div>
        <div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -60px;"></div>
        <div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -60px; left: 450px;"></div>
    </div>
    <div style="position: relative; left: 40px; height: 30px; top: 20px;">
        <div style="width: 300px; color: gray;">邮箱</div>
        <div style="width: 300px;position: relative; left: 200px; top: -20px;"><b>${clue.email}</b></div>
        <div style="width: 300px;position: relative; left: 450px; top: -40px; color: gray;">公司座机</div>
        <div style="width: 300px;position: relative; left: 650px; top: -60px;"><b>${clue.phone}</b></div>
        <div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -60px;"></div>
        <div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -60px; left: 450px;"></div>
    </div>
    <div style="position: relative; left: 40px; height: 30px; top: 30px;">
        <div style="width: 300px; color: gray;">公司网站</div>
        <div style="width: 300px;position: relative; left: 200px; top: -20px;"><b>${clue.website}</b></div>
        <div style="width: 300px;position: relative; left: 450px; top: -40px; color: gray;">手机</div>
        <div style="width: 300px;position: relative; left: 650px; top: -60px;"><b>${clue.mphone}</b></div>
        <div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -60px;"></div>
        <div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -60px; left: 450px;"></div>
    </div>
    <div style="position: relative; left: 40px; height: 30px; top: 40px;">
        <div style="width: 300px; color: gray;">线索状态</div>
        <div style="width: 300px;position: relative; left: 200px; top: -20px;"><b>${clue.state}</b></div>
        <div style="width: 300px;position: relative; left: 450px; top: -40px; color: gray;">线索来源</div>
        <div style="width: 300px;position: relative; left: 650px; top: -60px;"><b>${clue.source}</b></div>
        <div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -60px;"></div>
        <div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -60px; left: 450px;"></div>
    </div>
    <div style="position: relative; left: 40px; height: 30px; top: 50px;">
        <div style="width: 300px; color: gray;">创建者</div>
        <div style="width: 500px;position: relative; left: 200px; top: -20px;"><b>${clue.createBy}&nbsp;&nbsp;</b><small
                style="font-size: 10px; color: gray;">${clue.createTime}</small></div>
        <div style="height: 1px; width: 550px; background: #D5D5D5; position: relative; top: -20px;"></div>
    </div>
    <div style="position: relative; left: 40px; height: 30px; top: 60px;">
        <div style="width: 300px; color: gray;">修改者</div>
        <div style="width: 500px;position: relative; left: 200px; top: -20px;"><b>${clue.editBy}&nbsp;&nbsp;</b><small
                style="font-size: 10px; color: gray;">${clue.editTime}</small></div>
        <div style="height: 1px; width: 550px; background: #D5D5D5; position: relative; top: -20px;"></div>
    </div>
    <div style="position: relative; left: 40px; height: 30px; top: 70px;">
        <div style="width: 300px; color: gray;">描述</div>
        <div style="width: 630px;position: relative; left: 200px; top: -20px;">
            <b>
                ${clue.description}
            </b>
        </div>
        <div style="height: 1px; width: 850px; background: #D5D5D5; position: relative; top: -20px;"></div>
    </div>
    <div style="position: relative; left: 40px; height: 30px; top: 80px;">
        <div style="width: 300px; color: gray;">联系纪要</div>
        <div style="width: 630px;position: relative; left: 200px; top: -20px;">
            <b>
                ${clue.contactSummary}
            </b>
        </div>
        <div style="height: 1px; width: 850px; background: #D5D5D5; position: relative; top: -20px;"></div>
    </div>
    <div style="position: relative; left: 40px; height: 30px; top: 90px;">
        <div style="width: 300px; color: gray;">下次联系时间</div>
        <div style="width: 300px;position: relative; left: 200px; top: -20px;"><b>${clue.nextContactTime}</b></div>
        <div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -20px; "></div>
    </div>
    <div style="position: relative; left: 40px; height: 30px; top: 100px;">
        <div style="width: 300px; color: gray;">详细地址</div>
        <div style="width: 630px;position: relative; left: 200px; top: -20px;">
            <b>
                ${clue.address}
            </b>
        </div>
        <div style="height: 1px; width: 850px; background: #D5D5D5; position: relative; top: -20px;"></div>
    </div>
</div>

<!-- 备注 -->
<div id="remarkDivList" style="position: relative; top: 40px; left: 40px;">
    <div class="page-header">
        <h4>备注</h4>
    </div>
    <!--作业：显示备注信息-->
    <div id="remarks">

    </div>


    <div id="remarkDiv" style="background-color: #E6E6E6; width: 870px; height: 90px;">
        <form role="form" style="position: relative;top: 10px; left: 10px;">
            <textarea id="remark" class="form-control" style="width: 850px; resize : none;" rows="2"
                      placeholder="添加备注..."></textarea>
            <p id="cancelAndSaveBtn" style="position: relative;left: 737px; top: 10px; display: none;">
                <button id="cancelBtn" type="button" class="btn btn-default">取消</button>
                <button id="saveCreateClueRemarkBtn" type="button" class="btn btn-primary">保存</button>
            </p>
        </form>
    </div>
</div>

<!-- 市场活动 -->
<div>
    <div style="position: relative; top: 60px; left: 40px;">
        <div class="page-header">
            <h4>市场活动</h4>
        </div>
        <div style="position: relative;top: 0px;">
            <table class="table table-hover" style="width: 900px;">
                <thead>
                <tr style="color: #B3B3B3;">
                    <td>名称</td>
                    <td>开始日期</td>
                    <td>结束日期</td>
                    <td>所有者</td>
                    <td></td>
                </tr>
                </thead>
                <tbody id="relationTBody">

                </tbody>
            </table>
        </div>

        <div>
            <a id="bindActivityBtn" href="javascript:void(0);" style="text-decoration: none;"><span
                    class="glyphicon glyphicon-plus"></span>关联市场活动</a>
        </div>
    </div>
</div>


<div style="height: 200px;"></div>
</body>
</html>
